package net.hmr_radio.hmrbot.controller.bot.create;

import net.hmr_radio.hmrbot.controller.BaseLoggedInController;
import net.hmr_radio.hmrbot.model.Bot;
import net.hmr_radio.hmrbot.service.BotService;

import org.slim3.controller.Navigation;

import twitter4j.Twitter;

public class SuccessController extends BaseLoggedInController {

    private BotService botService = new BotService();

    @Override
    public Navigation doRun() throws Exception {

        Bot bot = sessionScope("auth");
        removeSessionScope("auth");
        botService.save(bot);

        Twitter twitter = bot.createTwitterOrNull();
        if (twitter != null) {
            bot.setTwitterId(twitter.getScreenName());
            botService.save(bot);
        }

        return forward("success.jsp");
    }
}
